package com.example.administrator.uiautomator.pages;

import android.support.test.uiautomator.UiObject2;

import com.example.administrator.uiautomator.utils.Finder;

/**
 * Created by Administrator on 2017/7/5.
 */

public class PageLogin {

    private Finder finder;

    public PageLogin(Finder finder){
        this.finder = finder;
    }

    public UiObject2 getNameEditText(){
        return finder.findById("com.netease.newsreader.activity:id/oy");
    }

    public UiObject2 getPwdEditText(){
        return finder.findById("com.netease.newsreader.activity:id/p4");
    }

    public UiObject2 getLoginBtn(){
        return finder.findById("com.netease.newsreader.activity:id/p6");
    }

    public void clickLogin(){
        getLoginBtn().click();
    }

    public void enterName(String name){
        getNameEditText().setText(name);
    }

    public void enterPwd(String pwd){
        getPwdEditText().setText(pwd);
    }

    public void clearNameEditText(){
        getNameEditText().clear();
    }

    public void clearPwdEditText(){
        getPwdEditText().clear();
    }

    public void login(String name,String pwd){
        clearNameEditText();
        enterName(name);
        getPwdEditText().click();
//        clearPwdEditText();
//        enterPwd(pwd);
        finder.enterPwd();
        clickLogin();
    }

    public UiObject2 getBackBtn(){
        return finder.findByContentDesc("Navigate up");
    }

    public void clickBackBtn(){
        getBackBtn().click();
    }

}
